package com.gjy.sb.disruptor;

import com.lmax.disruptor.EventHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 订单事件处理器 - 消费者
 *
 * @author gjy
 * @version 1.0
 * @since 2025-08-19 21:47:16
 */
@Component
public class OrderEventHandler implements EventHandler<OrderEvent> {
    private static final Logger log = LoggerFactory.getLogger(OrderEventHandler.class);

    @Override
    public void onEvent(OrderEvent event, long sequence, boolean endOfBatch) throws Exception {
        // 这里是处理事件的核心逻辑
        log.info("处理订单 - 序号: {}, 订单ID: {}, 商品: {}, 数量: {}, 价格: {}",
                sequence, event.getOrderId(), event.getProductName(), event.getQuantity(), event.getPrice());
        // 模拟耗时操作（如写数据库、调用外部服务）
        // Thread.sleep(10); // 实际应用中避免阻塞，可考虑异步处理
    }
}
